// components/col-card/col-card.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    colList: Object,
    type: Number
  },

  /**
   * 组件的初始数据
   */
  data: {
    isDark: ''
  },

  /**
   * 组件的方法列表
   */
  methods: {

     changePage(){
      let storageUserInfo = wx.getStorageSync('userInfo') ? wx.getStorageSync('userInfo'):null
      if (storageUserInfo==null) {
        this.getUserInfo()
      }else {

        if (this.data.type==1) {
          this.goTorReadingDetailed()
        }else {
          this.goToBookDetailed()
        }

      }

      
     },

    goToBookDetailed() {


      wx.navigateTo({
        url: '../../pages/bookdetailed/bookdetailed?id=' + this.properties.colList.book,
      })
    },

    goTorReadingDetailed(){
      wx.navigateTo({
        url: `/pages/readingdetailed/readingdetailed?sourceUuid=${this.data.colList.sourceUuid}&list=[]&bookName=${this.data.colList.v_book}&bookId=${this.data.colList.bookId}&cover=${this.data.colList.cover}`,
      })
    },

     // 登录
  getUserInfo() {
    
    wx.getUserProfile({
      desc: "获取你的昵称、头像、地区及性别", // 不写不弹提示框
      success: res => {
      
        wx.setStorageSync('userInfo',  res.userInfo)
      },
      fail: res => {
        //拒绝授权
        wx.showToast({
          title: '您拒绝了授权',
          icon: 'none'
        })
        return;
      }
    })
  }


  },


  lifetimes: {
    ready: function () {
      let storageDark = wx.getStorageSync('storageDark') ? wx.getStorageSync('storageDark') : false
      this.setData({
        isDark: storageDark
      })
    }
  }

})
